package com.jwt.mone.common;


import java.io.Serializable;
import java.util.HashMap;

public class Result implements Serializable {

    private String returnCode;
    private String returnMsg;
    private Object returnData;

    public String getReturnCode() {
        return returnCode;
    }

    public void setReturnCode(String returnCode) {
        this.returnCode = returnCode;
    }

    public String getReturnMsg() {
        return returnMsg;
    }

    public void setReturnMsg(String returnMsg) {
        this.returnMsg = returnMsg;
    }

    public Object getReturnData() {
        return returnData;
    }

    public void setReturnData(Object returnData) {
        this.returnData = returnData;
    }

    public Result() {
    }

    public static Result resultSuccess(String... msg) {
        return new Result(Constants.SUCCESS_CODE, Constants.SUCCESS_MSG, new HashMap());

    }


    public Result(String returnCode, String returnMsg) {
        this.returnCode = returnCode;
        this.returnMsg = returnMsg;
    }

    public Result(String returnCode, String returnMsg, Object returnData) {
        this.returnCode = returnCode;
        this.returnMsg = returnMsg;
        this.returnData = returnData;
    }

    public static Result success(String... msg) {
        if (msg.length == 0) {
            return new Result(Constants.SUCCESS_CODE, "操作成功");
        } else {
            return new Result(Constants.SUCCESS_CODE, msg[0]);
        }
    }


    public static Result success(Object returnData) {
        Result result = Result.success();
        result.setReturnData(returnData);
        return result;
    }


    /**
     * @param msg [] 错误消息(可选)，错误代码（可选），body  {} 空对象
     * @return
     */
    public static Result fail(String... msg) {
        if (msg.length == 1) {
            return new Result(msg[0], "");
        } else {
            return new Result(msg[0], msg[1]);
        }
    }

    public static Result failConclict(String... msg) {
        if (msg.length == 0) {
            return new Result(Constants.ERROR_CheckCODE, "该客户存在冲突");
        } else {
            return new Result(msg[0], msg[1]);
        }
    }

    public static Result resultfail(String code, String msg) {
        return new Result(code, msg, new HashMap());
    }


    @Override
    public String toString() {
        return "Result [returnCode=" + returnCode + ", returnMsg=" + returnMsg + ", returnData=" + returnData + "]";
    }

}
